<%@ Import Namespace="MVCWeb.Helpers" %>

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IPagedList<MVCWeb.Models.Community>>" %>

<%@ Register Src="~/Views/Menu/MainMenu.ascx" TagName="MainMenu" TagPrefix="mmuc" %>

<%@ Register Src="~/Views/Shared/LogOnUserControl.ascx" TagName="LogOnUserControl" TagPrefix="louc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Admin: List of communities</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script language="javascript" type="text/javascript">
        function ChangeStatus(CommunityId, CommunityName, status) {
            var s = 'active';
            if (status.toString() == "True") {
                s = 'deactive';
            }
            if (confirm("Are you sure that this community: " + CommunityName + " will be " + s + "?")) {
                // Perform change status.
                var action = '<%= Url.Action("ChangeStatus", "Community") %>/' + CommunityId;
                var request = new Sys.Net.WebRequest();
                request.set_httpVerb("POST");
                request.set_url(action);
                request.add_completed(ChangeStatusCompleted);
                request.invoke();
            }
        }

        function ChangeStatusCompleted() {
            // Reload page  
            window.location.reload();
        }    
    </script>

    <louc:LogOnUserControl ID="LogOnUserControl1" runat="server" />
<!-- BEGIN: MainMenu -->
    <mmuc:MainMenu ID="MainMenu1" runat="server" />
    <!-- END: MainMenu -->
    <br />
    <h3>
        Community List</h3>
    <table cellpadding="4" cellspacing="1" border="0" width="100%" class="DataTable">
        <tr>
        <th>
                ID
            </th>
            <th>
                Community Name
            </th>
            <th style="width: 1%">
                Action
            </th>
        </tr>
        <% foreach (var item in Model)
           {%>
        <tr>
            <td>
                <%=Html.Encode(item.CommunityId)%>
            </td>
            <td>
                <%=Html.Encode(item.Name)%>
            </td>
            <td style="white-space: nowrap">
                <%=Html.ActionLink("Edit", "Edit", new {id = item.CommunityId})%>
                | <a onclick="ChangeStatus(<%=item.CommunityId%>, '<%=item.Name%>', '<%=item.Active%>')" href="JavaScript:void(0)">
                    <%
                        if (item.Active.Value) {
                    %>
                    Active
                    <%
                        }
                    else
                    {%>
                    Deactive
                    <%
                    }%>
                </a>
            </td>
        </tr>
        <% } %>
    </table>
    <br />
    <div class="pager">
        <%= Html.Pager(ViewData.Model.PageSize, ViewData.Model.PageNumber, ViewData.Model.TotalItemCount) %>
    </div>
</asp:Content>
